package me.sealer.ssm.exception;

import me.sealer.ssm.constant.ErrorCodeConstant;
import me.sealer.ssm.core.MessageSupport;
import me.sealer.ssm.core.Messageable;

/**
 * 功能描述： $ SsmException
 *
 * @author sealer
 * @email 1178884049@qq.com
 * @date 2019年11月27日 09时36分49秒
 */
public class SsmException extends RuntimeException {
    private String returnCode;
    private Messageable messageable;

    public SsmException() {
        this(ErrorCodeConstant.SYSTEM_UNKNOWN_ERROR, null, new Object[0]);
    }

public SsmException(ErrorCodeConstant errorCodeConstant) {
        this(errorCodeConstant, null, new Object[0]);
    }

    public SsmException(Throwable cause) {
        this(ErrorCodeConstant.SYSTEM_UNKNOWN_ERROR, cause, new Object[0]);
    }

    public SsmException(ErrorCodeConstant errorCodeConstant, Object[] args) {
        this(errorCodeConstant, null, args);
    }

    public SsmException(ErrorCodeConstant errorCodeConstant, Throwable cause, Object[] args) {
        super(errorCodeConstant.getMessage(), cause);
        this.returnCode = errorCodeConstant.getReturnCode();

        String messageKey = errorCodeConstant.getMessage();
        String defaultMessage = errorCodeConstant.getDescription();

        messageable = new MessageSupport(messageKey, defaultMessage, args);
    }

    public String getReturnCode() {
        return returnCode;
    }

    public Messageable getMessageable() {
        return messageable;
    }
}
